package com.translation.gutenberg;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.concurrent.ConcurrentHashMap;

import com.translation.dao.BaseDAO;
import com.translation.dao.Selector;

public class Catalog extends ConcurrentHashMap<String, Integer> {

	private static final long serialVersionUID = 1L;

	private BaseDAO dao = new BaseDAO();

	public Catalog() {
		this(new BaseDAO());
	}

	public Catalog(BaseDAO dao) {
		super(3000000);
		init();
	};

	public static void main(String[] args) {
		new Catalog();
		System.out.println("Init Ok");
	}

	private void init() {
		System.out.println("Begin:" + System.currentTimeMillis());
		Selector selector = new Selector() {

			@Override
			public void setParams(PreparedStatement st) throws SQLException {
			}

			@Override
			public void row(ResultSet rs) throws SQLException {
				String s = rs.getString(1);
				put(s, 0);
			}
		};

		try {
			dao.select("select token from TOKEN", selector);
		} catch (Exception e) {
			e.printStackTrace();
		}

		System.out.println("End:" + System.currentTimeMillis() + "\nsize:" + this.size());
	}

}
